package com.zkk.service.impl;

import com.zkk.dao.StudentDao;
import com.zkk.dao.impl.StudentDaoImpl;
import com.zkk.pojo.PageUtil;
import com.zkk.pojo.Student;
import com.zkk.service.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    private StudentDao studentDao = new StudentDaoImpl();


    @Override
    public List<Student> findAll() {
        return studentDao.findAll();


    }

    @Override
    public Student add(Student student) {
        return studentDao.add(student);
    }

    @Override
    public int deleteById(int sid) {
        return studentDao.deleteById(sid);
    }


    @Override
    public Student selectById(int sid) {
        return studentDao.selectById(sid);
    }

    @Override
    public int update(Student student) {
        return studentDao.update(student);
    }



    @Override
    public PageUtil<Student> findAll(PageUtil<Student> studentPageUtil) {
        int currentPage = studentPageUtil.getCurrentPage();
        int pageSize = studentPageUtil.getPageSize();
        List<Student> list = studentDao.findAll((currentPage - 1) * pageSize, pageSize);
        //设置每页数据
        studentPageUtil.setDataPage(list);
        //设置总条数
        int count = studentDao.count();
        studentPageUtil.setCount(count);
        //设置总页数
        studentPageUtil.setSumPage((pageSize+count-1)/pageSize);
        return studentPageUtil;
    }
    //模糊查询的业务层
    @Override
    public PageUtil<Student> findAll(PageUtil<Student> studentPageUtil, String username) {
        int currentPage = studentPageUtil.getCurrentPage();
        int pageSize = studentPageUtil.getPageSize();
        List<Student> list = studentDao.findAll((currentPage - 1) * pageSize, pageSize,username);
        //设置每页数据
        studentPageUtil.setDataPage(list);
        //设置总条数
        int count = studentDao.count(username);
        studentPageUtil.setCount(count);
        //设置总页数
        studentPageUtil.setSumPage((pageSize+count-1)/pageSize);
        return studentPageUtil;
    }
}
